package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

public class AddPlayersDialog extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JPanel buttonPane;
	private JLabel label;
	private JTextArea textPane;
	private JButton okButton;
	private JButton cancelButton;
	private JButton addPlayerBtn;
	private JButton cancelBtn;
	private Frame frame;


	
	/**
	 * Create the dialog.
	 */
	public AddPlayersDialog(Frame frame) {
		this.frame = frame;
		setAlwaysOnTop(true);
		setVisible(false);
		initGui();
		makeComponents();
		makeButtonPanel();
		layoutComponents();
		initActionListeners();
	}
	
	private void initGui()
	{
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setLayout(new FlowLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		
	}
	
	private void makeComponents()
	{
		label = new JLabel();
		label.setText("<HTML>Voer hier de naam of namen in van de deelnemers, " +
				"gescheiden door een komma.<br> Vb. Jan Debakker, Els Deslager<br><br>Klik daarna op 'Spelers toevoegen'</HTML>");
		
			
		textPane = new JTextArea();	
		textPane.setColumns(5);
		
	}
	
	private void makeButtonPanel()
	{
		buttonPane = new JPanel();
		addPlayerBtn = new JButton("Spelers toevoegen");
		cancelBtn = new JButton("Annuleer");
		
		buttonPane.add(addPlayerBtn);
		buttonPane.add(cancelBtn);
	}
	
	private void layoutComponents()
	{
		contentPanel.setLayout(new BorderLayout());
		contentPanel.add(label, BorderLayout.NORTH);
		contentPanel.add(textPane, BorderLayout.CENTER);
		getContentPane().add(contentPanel, BorderLayout.CENTER);

		buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
		getContentPane().add(buttonPane, BorderLayout.SOUTH);
	}
	
	public void initActionListeners()
	{
		addPlayerBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				frame.getGuiController().getDomainController().addPlayers((textPane.getText()));
				setVisible(false);	
			}
		});
		
		cancelBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
				
			}
		});
	}

}
